﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.Unity;
using sonic.Samples.Infrastructure.Model;
using System.Collections.ObjectModel;
using System.Linq;

namespace sonic.Samples.Infrastructure.Services
{
    public class MockAccountService : IAccountService
    {
        private IUnityContainer container;
        private readonly ObservableCollection<Account> repository = new ObservableCollection<Account>();
        private string lastName = "Leftheris";

        public MockAccountService(IUnityContainer container)
        {
            this.container = container;
            this.repository.Add(new Account()
            {
                LastName = "Leftheris",
                FirstName = "Constantinos",
                Address = "Kazani D. 13, 11526 Athens, Greece",
                CurrentLocation = new Coordinates(37.952861, 23.712015),
                PastLocations = new ObservableCollection<Location>() { 
                    new Location("doctor",DateTime.Now.Subtract(new TimeSpan(10,0,0,0,0)), new Coordinates(23.7708289, 23.7708289)), 
                    new Location("meeting with someone",DateTime.Now.Subtract(new TimeSpan(8,0,0,0,0)), new Coordinates(23.2, 23.4))
                }
            });
            this.repository.Add(new Account()
            {
                LastName = "Michos",
                FirstName = "Achilleas",
                Address = "Chalandri, Greece",
                CurrentLocation = new Coordinates(30.01, 23.912015),
                PastLocations = new ObservableCollection<Location>() { 
                    new Location("doctor",DateTime.Now.Subtract(new TimeSpan(10,0,0,0,0)), new Coordinates(23.7708289, 23.7708289)), 
                    new Location("meeting with someone",DateTime.Now.Subtract(new TimeSpan(8,0,0,0,0)), new Coordinates(23.2, 23.4))
                }
            });
        }
        #region IAccountService Members

        public Account GetCurrent(string lastName)
        {
            return this.repository.Where(acc => acc.LastName.ToLower().Contains(lastName.ToLower())).FirstOrDefault();
        }

        public IEnumerable<Account> GetAll()
        {
            return repository;
        }

        #endregion

        #region IAccountService Members

        public Account GetCurrent()
        {
            if (lastName == null) return null;
            return this.repository.Where(acc => acc.LastName.ToLower().Contains(lastName.ToLower())).FirstOrDefault();
        }

        public void SetCurrent(string lastName)
        {
            this.lastName = lastName;
        }

        #endregion

    }
}
